PROJECT(XXEditor)
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.11)

#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
if (WIN32)
else()
    set(CMAKE_CXX_FLAGS "-std=c++11 -stdlib=libc++")
    set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stdlib=libc++")
endif()

add_subdirectory(Quick)

set(using_qt_libs Qt5Widgets Qt5Core Qt5Gui Qt5OpenGL)

foreach (lib ${using_qt_libs})
    find_package(${lib})
endforeach()

INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}/XXEditor)

set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)

set(XXUI_files
    XXEditor/BoxList.ui
    XXEditor/PathSetting.ui
    XXEditor/xxeditor.ui
)

set(XXUI_src_files
    ${CMAKE_CURRENT_SOURCE_DIR}/XXEditor/Accesser.cpp
    ${CMAKE_CURRENT_SOURCE_DIR}/XXEditor/AppDelegate.cpp
    ${CMAKE_CURRENT_SOURCE_DIR}/XXEditor/BoxList.cpp
    ${CMAKE_CURRENT_SOURCE_DIR}/XXEditor/Command.cpp
    ${CMAKE_CURRENT_SOURCE_DIR}/XXEditor/EditorScene.cpp
    ${CMAKE_CURRENT_SOURCE_DIR}/XXEditor/GLWidget.cpp
    ${CMAKE_CURRENT_SOURCE_DIR}/XXEditor/main.cpp
    ${CMAKE_CURRENT_SOURCE_DIR}/XXEditor/Options.cpp
    ${CMAKE_CURRENT_SOURCE_DIR}/XXEditor/PathSetting.cpp
    ${CMAKE_CURRENT_SOURCE_DIR}/XXEditor/Router.cpp
    ${CMAKE_CURRENT_SOURCE_DIR}/XXEditor/Selections.cpp
    ${CMAKE_CURRENT_SOURCE_DIR}/XXEditor/WidgetsMenu.cpp
    ${CMAKE_CURRENT_SOURCE_DIR}/XXEditor/xxeditor.cpp
    ${CMAKE_CURRENT_SOURCE_DIR}/XXEditor/XXLabel.cpp
    ${CMAKE_CURRENT_SOURCE_DIR}/XXEditor/XXUI_fix.cpp
    ${CMAKE_CURRENT_SOURCE_DIR}/XXEditor/ext/dfont/dfont_manager.cpp
    ${CMAKE_CURRENT_SOURCE_DIR}/XXEditor/ext/dfont/dfont_render.cpp
    ${CMAKE_CURRENT_SOURCE_DIR}/XXEditor/ext/dfont/dfont_utility.cpp
    ${CMAKE_CURRENT_SOURCE_DIR}/XXEditor/ccs/luabinding_ccs.cpp
    ${CMAKE_CURRENT_SOURCE_DIR}/XXEditor/ccs/XXUI_binding.cpp
    ${CMAKE_CURRENT_SOURCE_DIR}/XXEditor/ccs/luabinding.cpp
)

set(XXQRC_files
    XXEditor/xxeditor.qrc
)

set(include_dirs 
    XXEditor
    XXEditor/ext
    qtpropertybrowser/src
    ${cocos2d_include}
)


foreach (lib ${using_qt_libs})
    set(libname ${lib}_DEFINITIONS)
    set(incname ${lib}_INCLUDE_DIRS)
    add_definitions(${${libname}})
    list(APPEND include_dirs ${${libname}})
endforeach ()

add_definitions(-DCC_TARGET_OS_MAC)


#QT5_WRAP_CPP(Moc_files ${XXMOC_Files})
qt5_wrap_ui(Ui_files ${XXUI_files})
qt5_add_resources(Qrc_files ${XXQRC_files})

#message(${cocos2d_libdir})

set(libsdir
${cocos2d_libdir}
${CMAKE_CURRENT_SOURCE_DIR}/qtpropertybrowser/lib
)

if (WIN32)
    list(APPEND include_dirs ${CMAKE_CURRENT_SOURCE_DIR}/XXEditor/ext/freetype2/win32/include)
    list(APPEND libsdir XXEditor/ext/freetype2/win32/lib)
    list(APPEND XXUI_src_files ${CMAKE_CURRENT_SOURCE_DIR}/XXEditor/icon.rc)
else()
    list(APPEND libsdir XXEditor/ext/freetype2/mac)
    list(APPEND include_dirs ${CMAKE_CURRENT_SOURCE_DIR}/XXEditor/ext/freetype2/mac/include)
endif()

include_directories(
    ${include_dirs}
)

link_directories(${libsdir})

add_executable(XXEditor ${Moc_files} ${Ui_files} ${XXUI_src_files} ${Qrc_files})

if (WIN32)
    target_link_libraries(XXEditor libfreetype2)
    target_link_libraries(XXEditor QtSolutions_PropertyBrowser-headd)
else()
    target_link_libraries(XXEditor ${OPENGL_LIBRARIES})
    target_link_libraries(XXEditor ${zlib_LIBRARIES})
    #target_link_libraries(XXEditor ${curl_LIBRARIES})
    target_link_libraries(XXEditor -lfreetype)
    target_link_libraries(XXEditor -lQtSolutions_PropertyBrowser-head_debug)
endif()

target_link_libraries(XXEditor cocos2d-x)
if (WIN32)
else()
    SET_TARGET_PROPERTIES(XXEditor PROPERTIES OUTPUT_NAME "XXEditor.exe")
endif()

target_link_libraries(XXEditor Qt5::Gui)
target_link_libraries(XXEditor Qt5::Core)
target_link_libraries(XXEditor Qt5::Widgets)
target_link_libraries(XXEditor Qt5::OpenGL)
